package com.eternal.data.ui;

import android.content.Context;

import androidx.annotation.Nullable;
import android.util.AttributeSet;

import com.eternal.base.concat.TmpHum;
import com.eternal.base.global.BluetoothKey;
import com.eternal.base.protocol.ProtocolTransformer;
import com.eternal.framework.utils.KLog;

import java.math.RoundingMode;
import java.text.DecimalFormat;

public class GraphTmpView extends GraphView {
    private boolean isDegree=true;
    private DecimalFormat format;

    public GraphTmpView(Context context) {
        this(context, null);
    }

    public GraphTmpView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public GraphTmpView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        format=new DecimalFormat("#.0");
        format.setRoundingMode(RoundingMode.FLOOR);
    }

    public void setDegree(boolean isDegree){
        this.isDegree=isDegree;
    }

    @Override
    TimeValue getItem(int position) {
        TmpHum temp=adapter.getItem(position);
        return new TimeValue(temp.time, temp.getTmpValue());
    }

    @Override
    int getAvg() {
        return adapter.avgTmp;
    }

    @Override
    int getMax() {
        return adapter.aMaxTmp;
    }

    @Override
    int getMin() {
        return adapter.aMinTmp;
    }

    @Override
    String formatValue(int value) {
        if(isDegree){
            if(value== BluetoothKey.EMPTY){
                return "--℃";
            }
            return format.format(value/100f)+"℃";
        }
        if(value == BluetoothKey.EMPTY){
            return "--℉";
        }
        return format.format(ProtocolTransformer.getFah(value / 100f))+"℉";
    }

}
